<template>
	<view>
		<van-tabs active="current" @change="changeClassmate" color="#006600">
			<van-tab title="同班">
				<van-cell-group>
					<van-cell v-for="value in 10" :key="value" :title="classmateList.school" clickable
						@click="getClassmates" />
				</van-cell-group>
			</van-tab>
			<van-tab title="同级">
				aa
			</van-tab>
		</van-tabs>

		<van-notify id="van-notify" />
	</view>
</template>

<script>
	import Notify from '../../wxcomponents/vant/dist/notify/notify';
	export default {
		data() {
			return {
				current: 1,
				banji: "",
				college: "",
				grade: null,
				major: "",
				openid: "",
				school: "",
				classmateNum: null,
				classPageNo: 1,
				classmateList: []
			}
		},
		onLoad() {
			this.getMyInfo()
		},
		onPullDownRefresh() {
			wx.showNavigationBarLoading();
			this.classPageNo = 1;
			this.classmateList = [];
			this.getClassmates()
		},
		onReachBottom() {
			this.classPageNo++;
			this.getClassmates()
		},
		methods: {
			changeClassmate(e) {
				console.log(e.detail.name)
			},
			getMyInfo() {
				let self = this
				uni.request({
					url: getApp().globalData.baseURL + "/user/getUser",
					data: {
						"openid": wx.getStorageSync('openid')
					},
					header: {
						"token": wx.getStorageSync('token')
					},
					success: (res) => {
						self.banji = res.data.data.banji
						self.college = res.data.data.college
						self.grade = res.data.data.grade
						self.major = res.data.data.major
						self.school = res.data.data.school
						self.getClassmates()
					},
					fail: (err) => {
						Notify({
							type: 'danger',
							message: '请求失败,请检查您的网络连接',
						});
					}
				})
			},
			getClassmates() {
				let self = this
				uni.request({
					url: getApp().globalData.baseURL + "/user/selectByBanji",
					data: {
						"school": self.school,
						"college": self.college,
						"major": self.major,
						"grade": self.grade,
						"banji": self.banji
					},
					header: {
						"token": wx.getStorageSync('token')
					},
					success: (res) => {
						wx.hideNavigationBarLoading();
						wx.stopPullDownRefresh(); //停止下拉刷新
						self.classmateNum = res.data.data.length
						self.classmateList = res.data.data
						console.log(self.classmateList)
					},
					fail: (err) => {
						Notify({
							type: 'danger',
							message: '请求失败,请检查您的网络连接',
						});
					}
				})
			}
		}
	}
</script>

<style>

</style>
